package com.kqkj.dyrule.engine.util;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;
import java.sql.DriverManager;

/**
 * 各类查询库连接创建工具类
 */
public class ConnectionUtils {

    static Config config = ConfigFactory.load();

    public static Connection getHbaseConnection() throws IOException {
        System.out.println("hbase启动连接");
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.zookeeper.quorum",config.getString(ConfigNames.HABSE_ZK_QUORUM));
        Connection connection = ConnectionFactory.createConnection(configuration);
        System.out.println("hbase连接成功");
        return connection;
    }

    public static java.sql.Connection getCkConnection() throws Exception {
        System.out.println("ck启动连接");
        Class.forName(config.getString(ConfigNames.CK_JDBC_DRIVER));
        java.sql.Connection connection = DriverManager.getConnection(config.getString(ConfigNames.CK_JDBC_CONN));
        System.out.println("ck创建完成");
        return connection;

    }
}
